//
//  JWFindLoactionVC.m
//  jinwang
//
//  Created by jzb on 2018/4/4.
//  Copyright © 2018年 jzb. All rights reserved.
//

#import "JWFindLoactionVC.h"
#import "JWFBFacadeVCModel.h"
#import "JWFBFacadeTagVC.h"
#import "JWFindBusinessAddTagVC.h"

@interface JWFindLoactionVC ()

@property (nonatomic,strong) UIButton *AddressBtn;

@property (nonatomic, strong) MLMSegmentHead *segHead;
@property (nonatomic, strong) MLMSegmentScroll *segScroll;

@property (nonatomic, strong) NSMutableArray *ListmodelArr,*list;

@end

@implementation JWFindLoactionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"身边天下";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIBarButtonItem *AddressBtnItem = [[UIBarButtonItem alloc]initWithCustomView:self.AddressBtn];
    self.navigationItem.rightBarButtonItem = AddressBtnItem;
    
    [self makeUrl_Dynamic_defaultTag];
}

- (void)segHeadViewBuild{
    
    _list = [NSMutableArray new];
    
    for (int i = 0; i < _ListmodelArr.count; i++) {
        
        JWFBFacadeVCModel *model = _ListmodelArr[i];
        
        [_list addObject:model.tag_name];
    }
    _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRM(0, 64*2, 750-60*2, 88) titles:_list headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutLeft];
    //    _segHead.fontScale = 1.1;
    _segHead.fontSize = 17;
    _segHead.deSelectColor = kRGBColor(80, 80, 80);
    _segHead.selectColor = UIColorHex(0xEEA72B);
    _segHead.lineScale = .8;
    _segHead.bottomLineHeight = .5;
    _segHead.lineColor = UIColorHex(0xEEA72B);
    _segHead.bottomLineColor = kRGBColor(230, 230, 230);
    //    _segHead.moreButton_width = 60;
    
    UIButton *moreBtn = [[UIButton alloc]initWithFrame:CGRectMake(kScreenWidth-45, 64+4, 30, 30)];
    [moreBtn setImage:[UIImage imageNamed:@"jw_find_shop_blackAddIcom"] forState:UIControlStateNormal];
    [moreBtn addTarget:self action:@selector(moreBtnOnclick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:moreBtn];
    UIView *lineVeiw = [[UIView alloc]initWithFrame:CGRectMake(kScreenWidth - 60, 64+43.5, 60, .5)];
    lineVeiw.backgroundColor = kRGBColor(230, 230, 230);
    [self.view addSubview:lineVeiw];
    
    _segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRM(0, 88+64*2, 750, 1334-88-64*2) vcOrViews:[self vcArr:_list.count]];
    
    _segScroll.loadAll = YES;
    _segScroll.showIndex = 0;
    
    _segScroll.backgroundColor = [UIColor whiteColor];
    
    [MLMSegmentManager associateHead:_segHead withScroll:_segScroll completion:^{
        
        [self.view addSubview:_segHead];
        [self.view addSubview:_segScroll];
    }];
    
}
#pragma mark - 数据源
- (NSArray *)vcArr:(NSInteger)count {
    NSMutableArray *arr = [NSMutableArray array];
    for (int i = 0; i < _ListmodelArr.count; i++) {
        JWFBFacadeVCModel *model = _ListmodelArr[i];
        JWFBFacadeTagVC *FacadeTagVC = [[JWFBFacadeTagVC alloc]init];
        FacadeTagVC.tag_id = [model.tag_id stringValue];
//        FacadeTagVC.parent_id = _parent_id;
        
        [arr addObject:FacadeTagVC];
    }
    return arr;
}
- (void)moreBtnOnclick:(UIButton *)sender{
    
    JWFindBusinessAddTagVC *vc = [JWFindBusinessAddTagVC new];
    vc.title = @"身边天下";
    vc.ListmodelArr = _ListmodelArr;
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark -网络请求
//获取默认标签
-(void)makeUrl_Dynamic_defaultTag{
    [[DDNetworkManagerDate makeUrl_news_defaultTagWithtoken:k_user_token] post_RequestFinshSuccess:^(id responseObject) {
        
        NSLog(@"-=-=>>%@",responseObject);
        if ([self requestFinshCode:responseObject isShowMessage:NO] == 1) {
            _ListmodelArr = [NSMutableArray new];
            NSArray *data = [responseObject objectForKey:kRequsetDataKey];
            //转模型
            NSMutableArray *arr = [NSMutableArray array];
            [data enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                JWFBFacadeVCModel *model = [JWFBFacadeVCModel yy_modelWithDictionary:obj];
                [arr addObject:model];
            }];
            self.ListmodelArr = arr.mutableCopy;
            
            if (_ListmodelArr.count > 0) {
                
                [self segHeadViewBuild];
            }
            
        }
        
    } failure:^(id errorObject) {
        
        [self showBottomMessag:@"网络请求失败"];
    }];
}

- (void)AddressOnclick:(UIButton *)sender{
    
    
}
#pragma mark -懒加载
- (UIButton *)AddressBtn{
    if (!_AddressBtn) {
        _AddressBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _AddressBtn.frame = CGRectMake(0, 0, 44, 44);
        [_AddressBtn setImage:[UIImage imageNamed:@"jw_find_dingwei"] forState:UIControlStateNormal];
        [_AddressBtn addTarget:self action:@selector(AddressOnclick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _AddressBtn;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
